package serviceimpl;

import Tool.ToolInter;
import bean.Notice;
import dao.NoticeDaoInter;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import service.NoticeServiceInter;

import java.util.LinkedHashMap;
import java.util.List;

/**
 * Created by Administrator on 2017/4/25.
 */
public class NoticeServiceImpl implements NoticeServiceInter{


    private NoticeDaoInter noticeDaoImpl;
    private ToolInter toolImpl;

    public NoticeDaoInter getNoticeDaoImpl() {
        return noticeDaoImpl;
    }

    public void setNoticeDaoImpl(NoticeDaoInter noticeDaoImpl) {
        this.noticeDaoImpl = noticeDaoImpl;
    }

    

    public String queryAllNotice(){
        List<Notice> notice = this.getNoticeDaoImpl().queryAll();
        JSONArray jsonArray = new JSONArray();
        JSONObject obj = new JSONObject();
        JSONArray practiceReport = new JSONArray();
        for(int i = 0; i <notice.size();i++){
            LinkedHashMap report = new LinkedHashMap();
            try {
                report.put("nTitle",notice.get(i).getNtitle());
                report.put("nTime",this.getToolImpl().dateToString(notice.get(i).getNtime()));
                report.put("nContent",notice.get(i).getNcontent());
                report.put("nPicture",notice.get(i).getNpicture());
                JSONObject json =JSONObject.fromObject(report);
                practiceReport.add(json);
            } catch (Exception e){
                e.printStackTrace();
            }
        }
        obj.put("data",practiceReport);
        jsonArray.add(obj);
        return jsonArray.toString();

    }

	public ToolInter getToolImpl() {
		return toolImpl;
	}

	public void setToolImpl(ToolInter toolImpl) {
		this.toolImpl = toolImpl;
	}
}
